﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "IMepGenericElementType.h"
#include "IRoutingPreferenceManager.h"

namespace
{
    using gcmp::ElementId;
    using gcmp::ICalculatorCollection;
    using gcmp::ICopyContext;
    using gcmp::ICopyStrategyReporter;
    using gcmp::IDocument;
    using gcmp::IElement;
    using gcmp::IElementParentReporter;
    using gcmp::IParameter;
    using gcmp::Matrix4d;
    using gcmp::OwnerPtr;
    using gcmp::UniIdentity;
}

namespace gmep
{
    class IRoutingPreferenceManager;
    class IMepSize;
    enum class SectionType;
    class RoutingConditions;

    class GMEP_MODEL_INTERFACE_EXPORT IMepCurveType : public IMepGenericElementType
    {
        DEFINE_CAST_DERIVED(IMepCurveType, IMepGenericElementType)
    public:
        virtual ~IMepCurveType() {}

    public:
        virtual const IRoutingPreferenceManager* GetRoutingPreferenceManager() const = 0;
        virtual IRoutingPreferenceManager* GetRoutingPreferenceManager() = 0;

        virtual PreferredJunctionType GetPreferredJunctionType() const;
        virtual bool SetPreferredJunctionType(PreferredJunctionType junctionType);

        virtual double GetRoughness()const;
        virtual bool SetRoughness(double roughness);

        virtual SectionType GetSectionType()const = 0;

        virtual ElementId GetElbowTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetTeeTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetTapTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetTransitionTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetCrossTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetCapTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalInsideElbowsTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalOutsideElbowsTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalLateralJunctionsTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalLeftLateralElbowsTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalRightLateralElbowsTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetVerticalDownwardJunctionsTypeId(const RoutingConditions& conditions) const;
        virtual ElementId GetVerticalUpwardJunctionsTypeId(const RoutingConditions& conditions) const;
        virtual ElementId GetVerticalDownRightElbowTypeId(const RoutingConditions& conditions) const;
        virtual ElementId GetVerticalDownLeftElbowTypeId(const RoutingConditions & conditions) const;
        virtual ElementId GetUnionTypeId(const RoutingConditions& conditions) const;
        
        ///\brief 得到矩形到圆形过渡件类型Id
        ElementId GetTransitionRectangularToRoundTypeId() const;

        /// \brief 得到矩形到椭圆形过渡件类型Id
        ElementId GetTransitionRectangularToOvalTypeId() const;

        /// \brief 得到椭圆形到圆形过渡件类型Id
        ElementId GetTransitionOvalToRoundTypeId() const;

        /// \brief 设置和获取项目配置管理中对应的管材系列数据记录的唯一GUID，一般用于查询项目配置管理中的某个管材系列是否已经加载到当前工作单元
        virtual const gcmp::UniIdentity& GetProjectSettingRecordId() const = 0;
        virtual bool SetProjectSettingRecordId(const gcmp::UniIdentity& guidString) = 0;

        /// \brief 获取Implementation Uid
        ///
        /// \return UniIdentity 返回ImplementationUid
        static gcmp::UniIdentity GetImplementationUid();

    public:
        //以下是IExternalData需要重写的接口
        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override {};
        virtual void ReportParameterDefinitions(std::vector<int>* pParameterIds) const override {};
        virtual gcmp::OwnerPtr<IParameter> GetNativeParameter(int parameterId) const override;
        virtual bool SetNativeParameter(const IParameter *pParameter, std::wstring* errorMsg = nullptr) override { return false; };
        virtual bool IsParameterModifiable(int parameterId) const override { return true; };
        virtual void Report(const ICopyContext & copyContext, ICopyStrategyReporter& reporter) const override ;
        virtual void UpdateAfterCopy(const gcmp::ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override { return true; };

    private:
        ElementId GetMepPartId(RoutingPreferenceRuleGroupType groupType, const RoutingConditions& conditions) const;
        ElementId GetTapPartId(const RoutingConditions& conditions) const;
    };
}
